package com.wallet.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wallet.mappers.WalletMapper;
import com.wallet.entity.WalletEntity;
import com.wallet.service.WalletService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
/**
 * 钱包服务接口实现
 * @author zhangguangyuang
 */
@Service
public class WalletServiceImpl extends ServiceImpl<WalletMapper,WalletEntity> implements WalletService {

    @Resource
    private WalletMapper walletMapper;

    public BigDecimal getMoneyInWallet(Integer userId) {
        return walletMapper.getMoneyInWallet(userId);
    }

    @Transactional
    public boolean consumeHundred(Integer userId, BigDecimal decreaseMoney) {
        return walletMapper.decreaseMoneyInWallet(userId, decreaseMoney) > 0 ? true : false;
    }

    public WalletEntity getMoneyAndIdByUserId(Integer userId) {
        return walletMapper.getMoneyAndIdByUserId(userId);
    }

    @Transactional
    public boolean refundToWallet(WalletEntity wallet) {
        boolean res = walletMapper.refundToWallet(wallet) > 0 ? true : false;
        return res;
    }


}
